cd "C:\Users\au660726\Dropbox\jpart_expectations\additional analyses"
use "11-2017_survey_results.dta"


destring check1 check2, gen(check11 check22) ignore ("-")
drop check1 check2
rename check11 check1
rename check22 check2

*1 of soc_ref and hist_ref: 35 mins
*0 of soc_ref and hist_ref: 55 mins
*treatment = 1 --> social reference: 35 mins, historical reference: 35 mins
*treatment = 2 --> social reference: 55 mins, historical reference: 35 mins
*treatment = 3 --> social reference: 35 mins, historical reference: 55 mins
*treatment = 4 --> social refernece: 55 mins, historical reference: 55 mins
gen soc_ref = 1 if treatment == 1 | treatment ==3
replace soc_ref = 0 if treatment == 2 | treatment ==4
gen hist_ref = 1 if treatment == 1 | treatment ==2
replace hist_ref = 0 if treatment == 3 | treatment ==4
order soc_ref hist_ref, after(userlanguage)

gen norm_expt = 9 - norm_exp

gen pos_expt = 9 - pos_exp

order pos_expt norm_expt, after (norm_exp)
order soc_ref hist_ref, after(userlanguage)

replace satisf = satisf - 1

replace race = "6" if race == "1,2" | race=="1,2,6"|race=="1,2,3"|race=="1,6"|race=="1,5"|race=="1,6"|race=="1,4"|race=="1,2,5"|race=="4,5"|race=="1,3"|race=="1,2,6"
destring race, gen(race1)
drop race
rename race1 race

drop if dup_ipadd_matched >=1

*sex - 0:female/ 1:male
replace sex = sex - 1

tab party, gen(part_cat)
tab race, gen(race_cat)
tab income, gen(inc_cat)
tab age, gen(age_cat)
tab educ, gen(educ_cat)
tab region, gen(reg_cat)
tab sex, gen(sex_)

rename sex_1 female
rename sex_2 male
order female male, after(sex)


rename part_cat1 republican 
rename part_cat2 democrat
rename part_cat3 independence
rename part_cat4 other_party
order republican democrat independence other_party, after (partyln)

gen partisanship = 1 if republican ==1
replace partisanship = 5 if democrat == 1
replace partisanship = 3 if independence == 1 & partyln ==.
replace partisanship = 2 if independence == 1 & partyln == 1| other_party == 1 & partyln ==1
replace partisanship = 4 if independence == 1 & partyln == 2| other_party == 1 & partyln ==2
order partisanship, after (partyln)


tab partisanship, gen(pa_cat)
rename pa_cat1 rep
rename pa_cat2 rep_lean
rename pa_cat3 indpt
rename pa_cat4 dem_lean
rename pa_cat5 dem
order rep rep_lean indpt dem_lean dem, after (partisanship)


rename race_cat1 white
rename race_cat2 black
rename race_cat3 nat_ameri
rename race_cat4 asian 
rename race_cat5 pac_islander
rename race_cat6 multi

order white black nat_ameri asian pac_islander multi, after (race)

replace hisp = 0 if hisp == 2

rename inc_cat1 lessthan30k
rename inc_cat2 from30kto60k 
rename inc_cat3 from60kto90k
rename inc_cat4 morethan90k

order lessthan30k from30kto60k from60kto90k morethan90k, after (income)

rename age_cat1 from19to29
rename age_cat2 from30to49
rename age_cat3 from50to64
rename age_cat4 morethan65

order from19to29 from30to49 from50to64 morethan65, after(age)

rename educ_cat1 somehigh
rename educ_cat2 high
rename educ_cat3 somecollege
rename educ_cat4 college
rename educ_cat5 some_post
rename educ_cat6 grad
replace college =1 if some_post == 1
sum college

order somehigh high somecollege college some_post grad, after (educ)


rename reg_cat1 MW
rename reg_cat2 NE
rename reg_cat3 S
rename reg_cat4 W
order MW NE S W, after(region)

sum check1 if treatment ==1
sum check1 if treatment ==2
sum check1 if treatment ==3
sum check1 if treatment ==4
sum check2 if treatment ==1
sum check2 if treatment ==2
sum check2 if treatment ==3
sum check2 if treatment ==4
sum check3 if treatment ==1
sum check3 if treatment ==2
sum check3 if treatment ==3
sum check3 if treatment ==4
sum check4 if treatment ==1
sum check4 if treatment ==2
sum check4 if treatment ==3
sum check4 if treatment ==4

drop if check2 == 2030

replace white = 1 if white == 1 & hisp ==0
replace white = 0 if white == 1 & hisp ==1
replace black = 1 if black == 1 & hisp == 0
replace black = 0 if black == 1 & hisp ==1
replace nat_ameri = 1 if nat_ameri == 1 & hisp == 0 
replace nat_ameri = 0 if nat_ameri == 1 & hisp == 1
replace asian = 1 if asian == 1 & hisp == 0 
replace asian = 0 if asian ==1 & hisp ==1
replace pac_islander = 1 if pac_islander == 1 & hisp == 0 
replace pac_islander = 0 if pac_islander == 1 & hisp == 1

gen ethnic = 1 if white ==1
order ethnic, after(race)
replace ethnic = 2 if black ==1
replace ethnic = 3 if nat_ameri ==1
replace ethnic = 4 if asian ==1
replace ethnic = 5 if pac_islander ==1
replace ethnic = 6 if multi == 1
replace ethnic = 7 if hisp ==1

*Summary statistics (in online appendix)
outreg2 using TableOA-2.xls, replace sum(log) keep(soc_ref hist_ref pos_expt norm_expt satisf)
outreg2 using TableOA-3.xls, replace sum(log) keep(sex from19to29 from30to49 from50to64 morethan65 republican democrat independence other_party somehigh high somecollege college grad MW NE S W hisp white black nat_ameri asian pac_islander multi  lessthan30k from30kto60k from60kto90k morethan90k )

*Main results
reg norm_expt soc_ref hist_ref, robust
outreg2 using Table2.xls, ctitle(option_1) e(all) excel dec(3) bd(3) par(se) aster(coef) 

reg pos_expt soc_ref hist_ref, robust
outreg2 using Table2.xls, ctitle(option_2) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf soc_ref hist_ref, robust
outreg2 using Table3.xls, ctitle(option_1) e(all) excel dec(3) bd(3) par(se) aster(coef) 

reg satisf norm_expt soc_ref hist_ref, robust
outreg2 using Table3.xls, ctitle(option_2) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf pos_expt soc_ref hist_ref, robust
outreg2 using Table3.xls, ctitle(option_3) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf norm_expt pos_expt soc_ref hist_ref, robust
outreg2 using Table3.xls, ctitle(option_4) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf norm_expt


*Result graph
graph twoway (lfitci satisf norm_expt, fitplot(line) ciplot(rline) blpattern(shortdash)) (lfitci satisf pos_expt, fitplot(line) lpattern(longdash) ciplot(rline) blpattern(shortdash)), scheme(s1mono) title("") legend(order(2 "Normative Expectations" 4 "Predictive Expectations")) ytitle("Predicted Satisfaction") xtitle("Expectations") xlabel(1(1)8) ylabel(0(2)10)
graph export figure3.tif, width(2000)



***********************************************************************************************
**-------------------------------Analyses in online appendix---------------------------------**
***********************************************************************************************

*Instrument variable regressions
ivregress 2sls satisf (norm_expt = soc_ref), first vce(robust)
estat first
estat endogenous
outreg2 using TableOA-9, ctitle(option_1) e(all) excel dec(3) bd(3) par(se) aster(coef) 

ivregress 2sls satisf (pos_expt = hist_ref), first vce(robust)
estat first
estat endogenous
outreg2 using TableOA-9, ctitle(option_2) e(all) excel dec(3) bd(3) par(se) aster(coef) append

ivregress 2sls satisf (norm_expt pos_expt = soc_ref hist_ref), first vce(robust)
estat first
estat endogenous

outreg2 using TableOA-9, ctitle(option_3) e(all) excel dec(3) bd(3) par(se) aster(coef) append

outreg2 using summary3.xls, replace sum(log) keep(soc_ref hist_ref pos_expt norm_expt satisf sex from19to29 from30to49 from50to64 morethan65 republican democrat independence other_party somehigh high somecollege college some_post grad MW NE S W hisp white black nat_ameri asian pac_islander multi  lessthan30k from30kto60k from60kto90k morethan90k )

**Balance Test I - controlling for all demogrphic variables**
reg norm_expt soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust

outreg2 using TableOA-6.xls, ctitle(Normative expectations) e(all) excel dec(3) bd(3) par(se) aster(coef) 

reg pos_expt soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust
outreg2 using TableOA-6.xls, ctitle(Predictive expectations) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust
outreg2 using TableOA-7.xls, ctitle(Satisfaction) e(all) excel dec(3) bd(3) par(se) aster(coef) 

reg satisf norm_expt soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust
outreg2 using TableOA-7.xls, ctitle(Satisfaction) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf pos_expt soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust
outreg2 using TableOA-7.xls, ctitle(Satisfaction) e(all) excel dec(3) bd(3) par(se) aster(coef) append

reg satisf norm_expt pos_expt soc_ref hist_ref female age partisanship somehigh high somecollege college some_post grad MW NE S W white hisp income, robust
outreg2 using TableOA-7.xls, ctitle(Satisfaction) e(all) excel dec(3) bd(3) par(se) aster(coef) append

**Balance Test II using treatment variable - Oneway ANOVA**
oneway female treatment, tabulate
oneway age treatment, tabulate
oneway partisanship treatment, tabulate
oneway somehigh treatment, tabulate
oneway high treatment, tabulate
oneway somecollege treatment, tabulate
oneway college treatment, tabulate
oneway some_post treatment, tabulate
oneway grad treatment, tabulate
oneway MW treatment, tabulate
oneway NE treatment, tabulate
oneway S treatment, tabulate
oneway W treatment, tabulate
oneway white treatment, tabulate
oneway black treatment, tabulate
oneway nat_ameri treatment, tabulate
oneway asian treatment, tabulate
oneway pac_islander treatment, tabulate
oneway multi treatment, tabulate
oneway hisp treatment, tabulate
oneway income treatment, tabulate


//------------------------------------------------------------------------------------------------//

